package com.yixiu.study.juc.threadlocal;

import java.util.concurrent.TimeUnit;

/**
 * @CalssName T01_ThreadLocal
 * @Description
 * @Author yixiu
 * @Date 2021/6/28 11:01
 * @Verison 1.0
 **/
public class T01_ThreadLocal {

    static ThreadLocal<Person> t1 = new ThreadLocal<>();

    public static void main(String[] args) {
        new Thread(() -> {
            try {
                TimeUnit.SECONDS.sleep(2);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(t1.get());
        }).start();

        new Thread(() -> {
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            t1.set(new Person());
            System.out.println(t1.get());
        }).start();

    }


    static class Person{
        String name = "zhangsan";
    }

}
